package liill1.js_interface;

import android.webkit.JavascriptInterface;

import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustEvent;

import java.text.SimpleDateFormat;
import java.util.Locale;

public class AdjustToJavascript {
    /**
     * 激活事件
     * @param name 事件值-key
     */
    @JavascriptInterface
    public void Activation(String name){
//        AdjustEvent adjustEvent = new AdjustEvent("qdfpm9");
        AdjustEvent adjustEvent = new AdjustEvent(name);
        Adjust.trackEvent(adjustEvent);
    }
    /**
     * 注册事件
     * @param name 事件值-key
     */
    @JavascriptInterface
    public void register(String name){
//        AdjustEvent adjustEvent = new AdjustEvent("dnj6eu");
        AdjustEvent adjustEvent = new AdjustEvent(name);
        adjustEvent.addPartnerParameter("用户名","123");
        adjustEvent.addCallbackParameter("用户名","123");
        adjustEvent.addCallbackParameter("注册时间",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).toString());
        adjustEvent.addPartnerParameter("注册时间",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault()).toString());
        Adjust.trackEvent(adjustEvent);
    }

    /**
     * 首充事件
     * @param name 事件值-key
     * @param price 首充金额 -double类型
     */
    @JavascriptInterface
    public void FirstCharge(String name,double price){
//        AdjustEvent firstChargeEvent = new AdjustEvent("x22q8l");
        AdjustEvent firstChargeEvent = new AdjustEvent(name);
        firstChargeEvent.setRevenue(price, "USD");
        firstChargeEvent.setCallbackId(name);
        firstChargeEvent.addCallbackParameter("recharge_amount", String.valueOf(price));
        firstChargeEvent.addPartnerParameter("recharge_amount", String.valueOf(price));
        Adjust.trackEvent(firstChargeEvent);
    }

    /**
     * 二充事件
     * @param name 事件值-key
     * @param price 二充金额 -double类型
     */
    @JavascriptInterface
    public void SecondaryCharging(String name,double price){
//        AdjustEvent firstChargeEvent = new AdjustEvent("x22q8l");
        AdjustEvent secondaryChargingEvent = new AdjustEvent(name);
        secondaryChargingEvent.setRevenue(price, " USD");
        secondaryChargingEvent.setCallbackId(name);
        secondaryChargingEvent.addCallbackParameter("recharge_amount", String.valueOf(price));
        secondaryChargingEvent.addPartnerParameter("recharge_amount", String.valueOf(price));
        Adjust.trackEvent(secondaryChargingEvent);
    }
}
